# 对线程进行加锁
import threading

public_lock = threading.RLock()  # 可加锁多次   

loop = 100000  # 循环次数 
number = 0     # 公共变量


def addCount(counts):
    global number

    public_lock.acquire()  # 申请锁
    for i in range(counts):
        number += 1
    public_lock.release()   # 释放锁

def subCount(counts):
    global number

    public_lock.acquire()  # 申请锁
    for i in range(counts):
        number -= 1
    public_lock.release()   # 释放锁
    
t1 = threading.Thread(target=addCount, args=(loop, ))
t2 = threading.Thread(target=subCount, args=(loop, ))

t1.start()
t2.start()

print(number)
